/**
 * 
 */
package com.ums.core.service;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.ums.core.entity.user.User;

/**
 * @author soulMate
 *
 */
public class UserService  extends BaseService {

	public User createUser(User user) throws Exception {
		try {
			begingTransaction();
			getSession().save(user);
			endTransaction();
		} catch (Exception e) {
			setTransactionRollback();
			System.out.println("Error occurred while creating user: " + e);
		} 
		return user;
	}
	
	public List<User> searchUser(User user) throws Exception {
		List<User> users = null;
		try {
			Criteria crit = getSession().createCriteria(User.class);
			crit.add(Restrictions.like("username", "%" + user.getUsername() + "%"));
			users = crit.list();
			User user1 = null;
			
			for (Iterator it = users.iterator(); it.hasNext();) {
				user1 = (User) it.next();
				System.out.println(user1);
			}
		} catch (Exception e) {
			System.out.println("Error occurred while searching user: " + e);
		}
		return users;
	}
	
}
